package com.kch.system.service.impl;

import com.kch.system.domain.Train;
import com.kch.system.mapper.TrainMapper;
import com.kch.system.service.ITrainService;
import com.kch.system.vo.TrainVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TrainServiceImpl implements ITrainService {

    @Autowired
    private TrainMapper trainMapper;

    @Override
    public List<TrainVO> selectMeetingPage(Train train) {
        return trainMapper.selectMeetingPage(train);
    }

    @Override
    public int updateStatus(Integer id) {
        Train train = trainMapper.selectByPrimaryKey(id);
        String status = ("0".equals(train.getStatus())? "1" : "0");
        return trainMapper.updateStatus(train.getId(), status);
    }

    @Override
    public int insertSysTrain(Train train) {
        train.setStatus("1");
        train.setCreateTime(new Date());
        return trainMapper.insert(train);
    }

    @Override
    public int deleteTrain(String ids) {
        return trainMapper.deleteByPrimaryKey(Integer.valueOf(ids));
    }

    @Override
    public Train selectById(Integer id) {
        return trainMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateById(Train train) {
        Train exist = trainMapper.selectByPrimaryKey(train.getId());
        train.setCreateBy(exist.getCreateBy());
        train.setCreateTime(exist.getCreateTime());
        train.setStatus(exist.getStatus());
        return trainMapper.updateByPrimaryKeyWithBLOBs(train);
    }
}
